#!/bin/sh

qdate=`date -d 'last day' +%F`

if [ $# -eq 1 ];then
	qdate=$1
fi

echo $qdate is begin...



rm data/*$qdate.jieguo
zcat /logs/qunarlog/train/$qdate.gz|awk -v qdate=$qdate 'function abc(_str,_arr,_a,_b,_c,_d,_e,_f){split(_str,_a,"?"); split(_a[2],_c,"&"); for(_d in _c){split(_c[_d],_e,"="); _arr[_e[1]]=_e[2];}}{
	if($7~/\/stationToStation.htm?/)
	{
		delete arr;abc($7,arr);f=arr["fromStation"];t=arr["toStation"];gsub("\\\\x","%",f);gsub("\\\\x","%",t);xrr[f,t]++;
	}
	else if($7~/\/list_num.htm?/)
	{
		delete arr;abc($7,arr);f=arr["fromStation"];gsub("\\\\x","%",f);yrr[f]++;
	
	}
	else if($7~/\/station.htm?/)
	{
		delete arr;abc($7,arr);f=arr["fromStation"];gsub("\\\\x","%",f);zrr[f]++;

	}	
}END{
	for(x in xrr){split(x,trr,SUBSEP);print trr[1]","trr[2]","xrr[x] >> "data/s2s"qdate".jieguo"}
	for(y in yrr){print y","yrr[y]>>"data/t"qdate".jieguo"}
        for(z in zrr){print z","zrr[z]>>"data/s"qdate".jieguo"}
}'

